package com.aiyige.page.my.customer.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.aiyige.MyApp;
import com.aiyige.R;
import com.aiyige.model.Subject;
import com.alibaba.fastjson.annotation.JSONField;

/**
 * Created by xiachao on 2018/3/21.
 */

public class CustomerOrderEntity implements Parcelable {


    @JSONField(name="orderCode")
    String orderId;
    @JSONField(name="name")
    String orderName;
    @JSONField(name="type")
    String orderType;
    @JSONField(name="payMethod")
    String payMethod;
    @JSONField(name="status")
    String orderStatus;
    @JSONField(name="payTime")
    long payTime;
    @JSONField(name="amount")
    String amountReceivable;// 应收金额
    @JSONField(name="payAmount")
    String amountCollected; // 实收金额

    public CustomerOrderEntity() {

    }
    private CustomerOrderEntity(Builder builder) {
        setOrderId(builder.orderId);
        setOrderName(builder.orderName);
        setOrderType(builder.orderType);
        setPayMethod(builder.payMethod);
        setOrderStatus(builder.orderStatus);
        setPayTime(builder.payTime);
        setAmountReceivable(builder.amountReceivable);
        setAmountCollected(builder.amountCollected);
    }

    protected CustomerOrderEntity(Parcel in) {
        orderId = in.readString();
        orderName = in.readString();
        orderType = in.readString();
        payMethod = in.readString();
        orderStatus = in.readString();
        payTime = in.readLong();
        amountReceivable = in.readString();
        amountCollected = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(orderId);
        dest.writeString(orderName);
        dest.writeString(orderType);
        dest.writeString(payMethod);
        dest.writeString(orderStatus);
        dest.writeLong(payTime);
        dest.writeString(amountReceivable);
        dest.writeString(amountCollected);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<CustomerOrderEntity> CREATOR = new Creator<CustomerOrderEntity>() {
        @Override
        public CustomerOrderEntity createFromParcel(Parcel in) {
            return new CustomerOrderEntity(in);
        }

        @Override
        public CustomerOrderEntity[] newArray(int size) {
            return new CustomerOrderEntity[size];
        }
    };

    public static Builder newBuilder() {
        return new Builder();
    }


    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public void setOrderName(String orderName) {
        this.orderName = orderName;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    public void setPayMethod(String payMethod) {
        this.payMethod = payMethod;
    }

    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    public void setPayTime(long payTime) {
        this.payTime = payTime;
    }

    public void setAmountReceivable(String amountReceivable) {
        this.amountReceivable = amountReceivable;
    }

    public void setAmountCollected(String amountCollected) {
        this.amountCollected = amountCollected;
    }


    public String getOrderId() {
        return orderId == null ? "" : orderId;
    }


    public String getOrderName() {
        return orderName == null ? "" : orderName;
    }


    public String getOrderType() {
        return orderType == null ? "" : orderType;
    }


    public String getPayMethod() {
        return payMethod == null ? "" : payMethod;
    }

    public String getPayMethodName() {
        String payName = "";
        if (!TextUtils.isEmpty(getPayMethod())) {
            if (getPayMethod().equals("1") || getPayMethod().equals("5")) {
                payName = MyApp.getAppContext().getResources().getString(R.string.alipay);
            }
            else if (getPayMethod().equals("2") || getPayMethod().equals("6")) {
                payName = MyApp.getAppContext().getResources().getString(R.string.wechat);
            }
            else if (getPayMethod().equals("3")) {
                payName = MyApp.getAppContext().getResources().getString(R.string.bank_card);
            }
            else if (getPayMethod().equals("4")) {
                payName = MyApp.getAppContext().getResources().getString(R.string.apple_pay);
            }
        }
        return payName;
    }

    public String getOrderTypeName() {
        return Subject.getSubjectName(getOrderType());
    }



    public String getOrderStatus() {
        return orderStatus == null ? "" : orderStatus;
    }

    public String getOrderStatusName() {
        String statusName = "";
        if (!TextUtils.isEmpty(orderStatus) && orderStatus.equals("1")) {
            return MyApp.getAppContext().getResources().getString(R.string.payed);
        }
        return statusName;
    }

    public long getPayTime() {
        return payTime;
    }


    public String getAmountReceivable() {
        return amountReceivable == null ? "0" : amountReceivable;
    }


    public String getAmountCollected() {
        return amountCollected == null ? "0" : amountCollected;
    }

    public static final class Builder {
        private String orderId;
        private String orderName;
        private String orderType;
        private String payMethod;
        private String orderStatus;
        private long payTime;
        private String amountReceivable;
        private String amountCollected;

        private Builder() {
        }

        public Builder orderId(String orderId) {
            this.orderId = orderId;
            return this;
        }

        public Builder orderName(String orderName) {
            this.orderName = orderName;
            return this;
        }

        public Builder orderType(String orderType) {
            this.orderType = orderType;
            return this;
        }

        public Builder payMethod(String payMethod) {
            this.payMethod = payMethod;
            return this;
        }

        public Builder orderStatus(String orderStatus) {
            this.orderStatus = orderStatus;
            return this;
        }

        public Builder payTime(long payTime) {
            this.payTime = payTime;
            return this;
        }

        public Builder amountReceivable(String amountReceivable) {
            this.amountReceivable = amountReceivable;
            return this;
        }

        public Builder amountCollected(String amountCollected) {
            this.amountCollected = amountCollected;
            return this;
        }

        public CustomerOrderEntity build() {
            return new CustomerOrderEntity(this);
        }
    }
}
